import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:wangziyi_app/constans/constans.dart';
import 'package:wangziyi_app/constans/toast.dart';
import 'package:wangziyi_app/pages/setting_address_add.dart';
import 'package:wangziyi_app/widgets/my_text.dart';

class MyAddress extends StatefulWidget {
  @override
  _MyAddressState createState() => _MyAddressState();
}

class _MyAddressState extends State<MyAddress> {
  List addressName = ["王子异", "王子浩", "王子伟", "王子瑞", "王子琪", "张三"];
  List addressPhone = [
    "17665333272",
    "18244833709",
    "15386275728",
    "13715324563",
    "18684940193",
    "110"
  ];
  List addressTitele = [
    "湖南省怀化市芷江侗族自治县芷江镇芷秀园",
    "湖南省怀化市芷江侗族自治县芷江三里坪小学",
    "湖南省怀化市芷江侗族自治县芷江镇开发区和谐宾馆",
    "湖南省怀化市芷江侗族自治县芷江镇春阳摊宿舍",
    "湖南省怀化市芷江侗族自治县芷江镇东门口小学",
    "芷江军事基地",
  ];
  String _newValue = '默认地址0';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("我的收货地址"),
        centerTitle: true,
      ),
      body: Container(
        color: Color(AppColors.APP_BACKGROUND),
        child: ListView.builder(
            itemBuilder: (BuildContext context, int index) {
              return Container(
                alignment: Alignment.center,
                margin: EdgeInsets.all(15),
                decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.all(Radius.circular(10))),
                child: Column(
                  // mainAxisAlignment: MainAxisAlignment.center,
                  // crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    ListTile(
                      leading: Container(
                        height: 50,
                        width: 50,
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.all(Radius.circular(50)),
                          color: Color(0XFFFBE9E7),
                        ),
                        child: Container(
                            padding: EdgeInsets.all(5),
                            child: Center(
                                child: Text(
                              (addressName[index])[0],
                              style: TextStyle(
                                  fontWeight: FontWeight.w900,
                                  fontSize: 16,
                                  color: Colors.deepOrange),
                            ))),
                      ),
                      title: Row(
                        children: [
                          Text(addressName[index],
                              style: TextStyle(
                                  fontWeight: FontWeight.w900, fontSize: 20)),
                          SizedBox(
                            width: 10,
                          ),
                          Text(addressPhone[index],
                              style: TextStyle(
                                  fontWeight: FontWeight.w700,
                                  fontSize: 18,
                                  color: Colors.grey)),
                        ],
                      ),
                      subtitle: Text(
                        addressTitele[index],
                        style: TextStyle(color: Colors.black,
                            fontWeight: FontWeight.w900, fontSize: 16),
                      ),
                      trailing: const Icon(
                        Icons.edit_outlined,
                        color: Colors.grey,
                        size: 30,
                      ),
                      isThreeLine: true,
                    ),
                    Divider(height: 1,),
                    Row(
                      children: <Widget>[
                        Expanded(
                            child: RadioListTile<String>(
                          value: "默认地址$index",
                          title: MyText("默认地址", Colors.black, 15, 1),
                          groupValue: _newValue,
                          onChanged: (v) {
                            setState(() {
                              _newValue = v;
                            });
                          },
                          activeColor: Colors.deepOrange,
                        )),
                        Expanded(
                          child: GestureDetector(
                            child: Align(
                              child: MyText("删除", Colors.black, 15, 1),
                              alignment: Alignment.centerRight,
                            ),
                            onTap: () {
                              return showDialog(
                                  context: context,
                                  builder: (context) {
                                    return AlertDialog(
                                      content: MyText(
                                          "确定要删除该地址吗?", Colors.black, 15, 1),
                                      actions: <Widget>[
                                        FlatButton(
                                          child: Text('取消'),
                                          onPressed: () =>
                                              Navigator.pop(context),
                                        ),
                                        FlatButton(
                                            child: Text('确定'),
                                            onPressed: () {
                                              setState(() {
                                                addressName.removeAt(index);
                                                MyToast().toast("删除成功");
                                                _newValue = '默认地址';
                                              });
                                              Navigator.pop(context);
                                            }),
                                      ],
                                    );
                                  });
                            },
                          ),
                        ),
                        SizedBox(
                          width: 20,
                        )
                      ],
                    )
                  ],
                ),
              );
            },
            itemCount: addressName.length),
      ),
      bottomNavigationBar: Container(
        margin: EdgeInsets.all( 20),
        child: MaterialButton(

          shape: RoundedRectangleBorder(
              side: BorderSide.none, borderRadius: BorderRadius.circular(50)),
          height: 50,
          child: MyText("添加新地址", Colors.white, 20, 1),
          color: Colors.deepOrange,
          onPressed: () {

            Navigator.push(context, MaterialPageRoute(builder: (_){return AddAddress();}));
          },
        ),
      ),
    );
  }
}
